#pragma once
#include <Windows.h>
	class CTimer
	{
	private:
		LARGE_INTEGER _freq; // counts per second
		LARGE_INTEGER _start, _stop;
	public:
		explicit CTimer(DWORD_PTR affinity_mask = 1)
		{
			SetThreadAffinityMask(GetCurrentThread(), affinity_mask);
			QueryPerformanceFrequency(&_freq);
			QueryPerformanceCounter(&_start);
		}
		~CTimer(){}
		inline void restart(void){QueryPerformanceCounter(&_start);}
		inline double getElapsedTime(unsigned long nb_iterations = 1)
		{
			QueryPerformanceCounter(&_stop);
			double ret = (_stop.QuadPart - _start.QuadPart) / static_cast<double>(_freq.QuadPart);
			_start.QuadPart = _stop.QuadPart;
			return ret / static_cast<double>(nb_iterations);
		}
		inline double getTicks(void)
		{
			QueryPerformanceCounter(&_stop);
			double ret = static_cast<double>(_stop.QuadPart - _start.QuadPart);
			_start.QuadPart = _stop.QuadPart;
			return ret;
		}
	};
